const path = require('path')
const CopyWebpackPlugin = require('copy-webpack-plugin')

module.exports = {
  configureWebpack: {
    plugins: [
      new CopyWebpackPlugin([  // 自定义静态资源目录
        {
          from: path.join(__dirname,'static/images'),
          to: path.join(__dirname,'dist',process.env.NODE_ENV === 'production' ? 'build' : 'dev', process.env.UNI_PLATFORM, 'images')
        }
      ])
    ],
    resolve: {
      alias: {
        '@' resolve('static')
      }
    }
  },
  module: { // 图片压缩
      rules: [
          {
              test: /\.(png|jpe?g|gif|svg)$/i,
              use: [
                  {
                      loader: 'file-loader',
                      options: {
                          name: '[name].[ext]',
                          outputPath: 'images/'
                      }
                  },
                  {
                      loader: 'image-webpack-loader',
                      options: {
                          mozjpeg: {
                              progressive: true,
                              quality: 65
                          },
                          // optipng.enabled: false will disable optipng
                          optipng: {
                              enabled: false
                          },
                          pngquant: {
                              quality: [0.65, 0.90],
                              speed: 4
                          },
                          gifsicle: {
                              interlaced: false
                          },
                          // the webp option will enable WEBP
                          webp: {
                              quality: 75
                          }
                      }
                  }
              ]
          }
      ]
  }
}

